package com.mutual.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;

import com.mutual.base.page.PageResult;
import com.mutual.dao.IMemberDao;
import com.mutual.entity.Member;
import com.mutual.service.IMemberServer;

@Service
public class MemberServerImpl implements IMemberServer {

	@Resource
	private IMemberDao memberDao;
	
	public Member login(Member item){
		return memberDao.login(item);
	}
	
	public void listMemberByPage(PageResult<Member> pageResult,Member condition){
		int rows = memberDao.listMemberByPageCount(condition);
		pageResult.setRows(rows);

		RowBounds rowBounds = new RowBounds(pageResult.getCurrentPageIndex(),pageResult.getPageSize());
		List<Member> list = memberDao.listMemberByPage(rowBounds,condition);
		pageResult.setResult(list);
	}
	
	public Member getMemberById(String id){
		return memberDao.getMemberById(id);
	}

	public void add(Member item){
		memberDao.add(item);
	}

	public void update(Member item){
		memberDao.update(item);
	}

	@Override
	public void updateStatus(String splits,int status) {
		String[] split = splits.split(",");
		Member item = new Member();
		for (String id : split) {
			item.setId(id);
			item.setStatus(status);
			memberDao.updateStatus(item);
		}
	}

	@Override
	public List<Member> listByCondition(Member item) {
		return memberDao.listByCondition(item);
	}
	
}
